package com.cloudsigns.factorymanager2.produce.presenter.produce_team;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.bean.WorkPartBean;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartOrderResponse;
import com.cloudsigns.factorymanager2.produce.iview.produce_team.IGetProductWorkPartAssignDoneOrderListView;
import com.cloudsigns.factorymanager2.produce.model.produce_team.GetProductWorkPartAssignDoneOrderListModel;
import com.cloudsigns.factorymanager2.produce.model.produce_team.IGetProductWorkPartAssignDoneOrderListModel;

import java.util.List;

public class GetProductWorkPartAssignDoneOrderListPresenter {
    private IGetProductWorkPartAssignDoneOrderListView view;
    private IGetProductWorkPartAssignDoneOrderListModel model;
    private Handler handler = new Handler();

    public GetProductWorkPartAssignDoneOrderListPresenter(IGetProductWorkPartAssignDoneOrderListView view) {
        this.view = view;
        this.model = new GetProductWorkPartAssignDoneOrderListModel();
    }

    public void getProductWorkPartAssignDoneOrderList() {
        view.showLoading();

        model.getProductWorkPartAssignDoneOrderList(new GetProductWorkPartAssignDoneOrderListModel.OnGetProductWorkPartAssignDoneOrderListListener() {
            @Override
            public void getDataSuccessed(final List<WorkPartOrderResponse> workPartOrderResponseList) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getGetProductWorkPartAssignDoneOrderListSuccessed(workPartOrderResponseList);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void getDataFailed(final String desc) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getGetProductWorkPartAssignDoneOrderListFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
